package com.ruoyi.business.modbus.domain;

import java.util.List;

/**
 * Modbus操作响应封装类
 * 
 * @author ruoyi
 * @date 2024-01-01
 * @param <T> 数据类型
 */
public class ModbusReadResponse<T> {
    
    /**
     * 操作是否成功
     */
    private boolean success;
    
    /**
     * 提示信息
     */
    private String message;
    
    

    
    /**
     * 返回的数据列表
     */
    private List<T> data;
    
    /**
     * 设备编码
     */
    private String deviceSN;
    
    /**
     * 操作时间戳
     */
    private long timestamp;
    
    public ModbusReadResponse() {
        this.timestamp = System.currentTimeMillis();
    }
    
    /**
     * 成功响应构造方法
     */
    public static <T> ModbusReadResponse<T> success(String message, List<T> data, String deviceSN) {
        ModbusReadResponse<T> response = new ModbusReadResponse<>();
        response.success = true;
        response.message = message;
        response.data = data;
        response.deviceSN = deviceSN;
        return response;
    }
    

    
    /**
     * 失败响应构造方法
     */
    public static <T> ModbusReadResponse<T> failure(String message, String deviceSN) {
        ModbusReadResponse<T> response = new ModbusReadResponse<>();
        response.success = false;
        response.message = message;
        response.deviceSN = deviceSN;
        return response;
    }
    
    // Getters and Setters
    public boolean isSuccess() {
        return success;
    }
    
    public void setSuccess(boolean success) {
        this.success = success;
    }
    
    public String getMessage() {
        return message;
    }
    
    public void setMessage(String message) {
        this.message = message;
    }
    

    
    public List<T> getData() {
        return data;
    }
    
    public void setData(List<T> data) {
        this.data = data;
    }
    
    public String getDeviceSN() {
        return deviceSN;
    }
    
    public void setDeviceSN(String deviceSN) {
        this.deviceSN = deviceSN;
    }
    
    public long getTimestamp() {
        return timestamp;
    }
    
    public void setTimestamp(long timestamp) {
        this.timestamp = timestamp;
    }
    
    @Override
    public String toString() {
        return "ModbusReadResponse{" +
                "success=" + success +
                ", message='" + message + '\'' +
                ", data=" + data +
                ", deviceSN='" + deviceSN + '\'' +
                ", timestamp=" + timestamp +
                '}';
    }
}
